﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RFID测试软件
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class RfidTestWindow : Window
    {
        private ViewModel.RfidTestViewModel viewModel = new ViewModel.RfidTestViewModel();
        private View.TestView testView = new View.TestView();
        private View.DataView dataView = new View.DataView();
        public RfidTestWindow()
        {
            //设置为中文
            HandyControl.Tools.ConfigHelper.Instance.SetLang("zh-cn");
            InitializeComponent();
            this.DataContext = viewModel;
            //启动默认选择测试页面
            viewModel.MenuViewModel.TestMenuColor = BtLabelModel.ColorModel.SelectBlue;
            viewModel.MenuViewModel.QureyMenuColor = Brushes.DodgerBlue;
            GridMain.Children.Clear();
            GridMain.Children.Add(testView);
        }

        private void TitleBar_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }
        int i = 0;
        private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
        {
            i += 1;
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 0, 300);
            timer.Tick += (s, e1) => { timer.IsEnabled = false; i = 0; };
            timer.IsEnabled = true;
            if (i % 2 == 0)
            {
                timer.IsEnabled = false;
                i = 0;
                this.WindowState = this.WindowState == WindowState.Maximized ?
                              WindowState.Normal : WindowState.Maximized;
            }
        }

        private void PackIcon_MouseLeave(object sender, MouseEventArgs e)
        {
            if (Cursor != Cursors.Wait)
            {
                Cursor = Cursors.Arrow;
            }

        }

        private void PackIcon_MouseMove(object sender, MouseEventArgs e)
        {
            if (Cursor != Cursors.Wait)
            {
                Cursor = Cursors.Hand;
            }
        }

        private void PackIconMin_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.WindowState = WindowState.Minimized; //设置窗口最小化
        }

        private void PackIconClose_MouseDown(object sender, MouseButtonEventArgs e)
        {
            System.Environment.Exit(0);
        }

        private void Menu_MouseLeave(object sender, MouseEventArgs e)
        {
            Border border = sender as Border;
            if (border.Background != BtLabelModel.ColorModel.SelectBlue)
            {
                border.Background = Brushes.DodgerBlue;
            }
        }

        private void Menu_MouseMove(object sender, MouseEventArgs e)
        {
            Border border = sender as Border;
            if (border.Background != BtLabelModel.ColorModel.SelectBlue)
            {
                border.Background = BtLabelModel.ColorModel.MoveBlue;
            }
        }

        private void TestMenu_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Border border = sender as Border;
            if (border.Background != BtLabelModel.ColorModel.SelectBlue)
            {
                viewModel.MenuViewModel.TestMenuColor = BtLabelModel.ColorModel.SelectBlue;
                viewModel.MenuViewModel.QureyMenuColor = Brushes.DodgerBlue;
                GridMain.Children.Clear();
                GridMain.Children.Add(testView);
            }
        }

        private void QueryMenu_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Border border = sender as Border;
            if (border.Background != BtLabelModel.ColorModel.SelectBlue)
            {
                viewModel.MenuViewModel.QureyMenuColor = BtLabelModel.ColorModel.SelectBlue;
                viewModel.MenuViewModel.TestMenuColor = Brushes.DodgerBlue;
                GridMain.Children.Clear();
                GridMain.Children.Add(dataView);
            }
        }
    }
}
